1. Technical Field
The present application relates generally to an improved data processing system and method. More specifically, the present application is directed to a system and method for instantiating an interface or abstract class in application code.
2. Description of Related Art
In object-oriented programming, classes are used to group related variables and functions. A class describes a collection of encapsulated instance variables and methods (functions), possibly with implementation of those types together with a constructor function that can be used to create objects of the class.
A class is a cohesive package that consists of a particular kind of compile-time metadata. A class describes the rules by which objects, i.e. instances of the class, behave. The class specifies the structure of data which each instance of the class, i.e. an object, contains as well as the methods which manipulate the data of the object and perform tasks. A method is a function with a special property that it has access to data stored in an object.
Instances of a class, i.e. objects, will have certain aspects, i.e. features, attributes or properties, in common. One of the benefits of programming with classes is that all instances of a particular class will follow the defined behavior of the class they instantiate.
A class can “implement” (or “realize”) multiple interfaces, each of which specify one or more abstract method signatures (name and type of the method and its parameters) which must be defined in that class. Unlike multiple inheritance where actual code is inherited (along with naming and logical conflicts) interfacing allows one to define a behavior-interface (methods) that all classes implementing the interface should be able to fulfill.
Interfaces are a type of abstract class. Abstract classes, or abstract base classes (ABCs), are classes that are designed only as a parent class and from which child classes may be derived, and which is not itself suitable for instantiation. Concrete classes, on the other hand, are classes for which instances, i.e. objects, may be created. Abstract classes are often used to represent abstract concepts or entities. The incomplete features of the abstract class are then shared by a group of sibling sub-classes which add different variations of the missing pieces.
Interfaces and abstract classes allow for separation of concerns and inter-operability when architecting and developing applications. The interfaces and abstract classes must be implemented in concrete classes when generating such applications. Such implementation of interfaces and abstract classes requires “hard coding” of the interface or abstract class implementation in the concrete class. As a result, if the interface or abstract class implementation is to be replaced, a source code update and recompilation would be necessary.
Consider the following example where an AudioDevice interface is provided and two concrete classes “Radio” and “MP3Player” implementing the AudioDevice interface are provided:
public interface AudioDevice {public void play( ) throws playbackException;public void stop( ) throws discontinuationException;}public class Radio implements AudioDevice {public void play( ) throws playbackException {...}public void stop( ) throws discontinuationException{...}}public class MP3Player implements AudioDevice {public void play( ) throws playbackException{...}public void stop( ) throws discontinuationException{...}public void shuffle( ) {...}}Consider also the following snippet of application source code:
...[36] AudioDevice myStereo = new MP3Player( );[37] myStereo.play( );...[52] myStereo.stop( );...
As shown in the example, the instantiation of the AudioDevice interface requires the specification in the application source code of a concrete class that implements the interface. As a result, if a programmer later wishes to switch to alternate implementations of the AudioDevice interface, the programmer must modify the application source code itself to change the concrete class implementation of the interface. For example, if a new MP3 PDA combination device is to be utilized, a new concrete class for the MP3 PDA combination device must be provided and the application source code must be modified as follows to implement the AudioDevice interface using the new MP3PDA concrete class:
[36] AudioDevice myStereo=new MP3PDA( );
Even a single application source code change, such as the one above, still requires new development of application source code and a recompilation of the application source code. Such development and recompilation takes time, effort, and resources to accomplish. This is made even more troublesome when considered in light of modern applications where there may be thousands of lines of application source code.